#include "../../header.h"
#include <sqlite3.h>
int main(int argc, char const *argv[])
{
    sqlite3 *db;
    if(sqlite3_open("stur.db",&db)<0)
    {
        printf("数据库文件打开失败:%s\n",sqlite3_errmsg(db));
        return -1;
    }
    /* const char * insert_str = "insert into stu values(\'王五\',23,98);";
    char *errmsg = NULL;
    if(sqlite3_exec(db,insert_str,NULL,NULL,&errmsg)!=SQLITE_OK)
    {
        printf("插入数据失败:%s\n",sqlite3_errmsg(db));
        sqlite3_close(db);
        return -1;
    }
    printf("插入数据成功\n"); */
    const char * get_table_str = "select * from stu;";
    char **result = NULL;
    char *errmsg = NULL;
    int nrow ,ncolumn;
    if(sqlite3_get_table(db,get_table_str,&result,&nrow,&ncolumn,&errmsg)!=SQLITE_OK)
    {
        printf("获取表格失败:%s\n",sqlite3_errmsg(db));
        sqlite3_close(db);
        return -1;
    }
    printf("本表格是%d行 %d列的数据\n",nrow,ncolumn);
    int index = 0;
    index = ncolumn;
    for(int i=0;i<nrow;i++)
    {
        for(int j=0;j<ncolumn;j++)
        {
            printf("%s : %s\n",result[j],result[index++]);
        }
    }
    sqlite3_close(db);
    return 0;
}
